package com.huarun.module.visitorApply.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.huarun.common.BaseController;
import com.huarun.common.ResponseMessage;
import com.huarun.common.util.*;
import com.huarun.module.applyrecord.bean.ApplyRecord;
import com.huarun.module.applyrecord.service.IApplyRecordService;
import com.huarun.module.user.bean.User;
import com.huarun.module.user.service.IUserService;
import com.huarun.module.visitorApply.bean.ValidateInfo;
import com.huarun.module.visitorApply.bean.Visitor;
import com.huarun.module.visitorApply.bean.VisitorApply;
import com.huarun.module.visitorApply.service.ValidateInfoService;
import com.huarun.module.visitorApply.service.VisitorApplyService;
import com.huarun.redis.RedisKeyPrefix;
import com.huarun.redis.RedisService;
import com.huarun.redis.RedisUtils;
import io.swagger.annotations.ApiOperation;

import java.io.PrintStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping({"/wx/newVisitorApply"})
public class VisitorApplyController extends BaseController {

    @Resource
    private IUserService userService;

    @Resource
    private VisitorApplyService visitorApplyService;

    @Resource
    private IApplyRecordService applyRecordService;

    @Resource
    private ValidateInfoService validateInfoService;

    public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @ApiOperation(value = "根据手机号获取被访人信息", notes = "被访人")
    @RequestMapping(value = {"/invitedinfo"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> invitedinfo(HttpServletRequest request, @RequestBody Map<String, Object> userParam) {
        ResponseMessage rm = new ResponseMessage();
        String projectId = request.getHeader("projectId");
        Map parames = new HashMap();
        JSONObject jsonEmployee = new JSONObject();
        String mobile = String.valueOf(userParam.get("mobile"));
        if (projectId.equals(PropertyUtil.getProperty("chunsun_project_id"))) {
            String buildingName = "中国华润大厦";
            long time = System.currentTimeMillis();
            String sign_key = PropertyUtil.getProperty("sign_key");

            Map map = new HashMap();
            map.put("time", Long.valueOf(time));
            map.put("mobile", mobile);
            Gson gson = new Gson();
            String str = gson.toJson(map);
            str = str + "&key=" + sign_key;
            String token = crypt(str).toUpperCase();

            jsonEmployee.put("sign", token);
            jsonEmployee.put("time", Long.valueOf(time));
            jsonEmployee.put("mobile", mobile);

            String url = PropertyUtil.getProperty("visitor_a_url") + PropertyUtil.getProperty("chunsun_employee_url");

            JSONObject employee = HttpRequestUtils.httpPost(url, jsonEmployee);
            System.out.println("==============春笋预约返回:" + (employee == null ? "null" : employee.toJSONString()));
            if (employee != null) {
                JSONObject retdataJson = employee.getJSONObject("Retdata");
                String floor = retdataJson.getString("floor");
                retdataJson.replace("buildingName", buildingName);
                retdataJson.replace("complexFloor", floor);
                employee.put("isDegree", Integer.valueOf(0));
                rm.setData(employee);
            } else {
                String abc = "{\"errcode\":0,\"Retdata\":{\"flag\":\"-1\"},\"isDegree\":0,\"errmsg\":\"OK\"}";
                JSONObject parseObject = JSONObject.parseObject(abc);
                rm.setData(parseObject);
                return rm;
            }
        } else if ((projectId.equals(PropertyUtil.getProperty("huarun_d_project_id"))) ||
                (projectId.equals(PropertyUtil.getProperty("huarun_b_project_id"))) ||
                (projectId.equals(PropertyUtil.getProperty("huarun_c_project_id")))) {
            parames.put("mobile", mobile);
            parames.put("projectId", projectId);
            Map subject = this.visitorApplyService.getDepartment(parames);
            String department = "";
            String userName = "";
            String telPhone = "";
            if (subject.size() > 0) {
                department = (String) subject.get("department");
                userName = (String) subject.get("real_name");
                telPhone = (String) subject.get("phone");
            } else {
                String abc = "{\"errcode\":0,\"Retdata\":{\"flag\":\"-1\"},\"isDegree\":0,\"errmsg\":\"OK\"}";
                JSONObject parseObject = JSONObject.parseObject(abc);
                rm.setData(parseObject);
                return rm;
            }

            long time = new Date().getTime();

            String str = "/ThirdPart/api/v1/ProjectLessee/GetLesseeInfoByName/" + projectId + "/" +
                    URLUtil.encodeURIComponent(department) +
                    "appkey=" + PropertyUtil.getProperty("manage_appkey") + "&time=" + time +
                    PropertyUtil.getProperty("manage_secret");

            String token = MD5Util.getMD5Uppercase(str);

            String url = Constant.BASE_URL + "/ThirdPart/api/v1/ProjectLessee/GetLesseeInfoByName/" + projectId + "/" +
                    URLUtil.encodeURIComponent(department) +
                    "?appkey=" + PropertyUtil.getProperty("manage_appkey") + "&time=" + time + "&token=" + token;
            try {
                String doGet = HttpUtil.doGet(url);
                JSONArray jsonArray = JSONObject.parseObject(doGet).getJSONObject("Data").getJSONArray("LesseeInfo");

                JSONArray roomInfo = new JSONArray();
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject jo = (JSONObject) JSON.toJSON(jsonArray.get(i));
                    roomInfo = jo.getJSONArray("RoomInfo");
                }
                StringBuilder complexFloor = new StringBuilder();
                String buildingName = "";
                if (projectId.equals(PropertyUtil.getProperty("huarun_b_project_id")))
                    buildingName = "华润置地大厦B座";
                else if (projectId.equals(PropertyUtil.getProperty("huarun_c_project_id")))
                    buildingName = "华润置地大厦C座";
                else if (projectId.equals(PropertyUtil.getProperty("huarun_d_project_id"))) {
                    buildingName = "华润置地大厦D座";
                }
                if ((roomInfo != null) && (roomInfo.size() != 0)) {
                    for (int i = 0; i < roomInfo.size(); i++) {
                        JSONObject jo = (JSONObject) JSON.toJSON(roomInfo.get(i));
                        complexFloor.append(jo.getString("FloorName")).append(",");
                    }
                }
                complexFloor = new StringBuilder(complexFloor.substring(0, complexFloor.length() - 1));
                String[] split = complexFloor.toString().split(",");

                Set<String> set = new HashSet();
                set.addAll(Arrays.asList(split));
                String[] arrayResult = set.toArray(new String[0]);

                String floor = "";
                for (String string : arrayResult) {
                    floor = floor + string + ",";
                }
                floor = floor.length() > 0 ? floor.substring(0, floor.length() - 1) : "";
                String abc = "{\"errcode\":0,\"Retdata\":{\"flag\":\"1\",\"complexFloor\":\"1F,2F,3F\",\"buildingName\":\"建筑名称\",\"empName\":\"员工姓名\",\"tel\":\"13800138000\"},\"isDegree\":0,\"errmsg\":\"OK\"}";
                JSONObject parseObject = JSONObject.parseObject(abc);
                parseObject.getJSONObject("Retdata").replace("flag", Integer.valueOf(1));
                parseObject.getJSONObject("Retdata").replace("complexFloor", floor);
                parseObject.getJSONObject("Retdata").replace("buildingName", buildingName);
                parseObject.getJSONObject("Retdata").replace("empName", userName);
                parseObject.getJSONObject("Retdata").replace("tel", telPhone);
                rm.setData(parseObject);
            } catch (Exception e) {
                e.printStackTrace();
                rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
                return rm;
            }

        }

        return rm;
    }

    @ApiOperation(value = "访客预约申请", notes = "访客预约")
    @RequestMapping(value = {"/saveVisitorApply"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> saveVisitorApply(@RequestBody JSONObject param, HttpServletRequest request, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer rows) {
        ResponseMessage rm = new ResponseMessage();
        String projectId = request.getHeader("projectId");
        Visitor visitor = JSON.parseObject(param.toJSONString(), Visitor.class);
        visitor.setVisitorNum(1); //一人一码
        if (StringUtils.isBlank(visitor.getVisitorName())) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "来访人名字不能为空");
            return rm;
        }
        if (StringUtils.isBlank(visitor.getVisitorPhone())) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "来访人手机号码不能为空");
            return rm;
        }
        if ((StringUtils.isBlank(visitor.getStartTime())) || (StringUtils.isBlank(visitor.getEndTime()))) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "时间不能为空");
            return rm;
        }
        if (StringUtils.isBlank(visitor.getVisited())) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "被访人姓名不能为空");
            return rm;
        }
        if (StringUtils.isBlank(visitor.getVisitedPhone())) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "被访人手机号码不能为空");
            return rm;
        }

        Map<String, Object> userParam = new HashMap();
        userParam.put("openId", request.getHeader("openId"));
        userParam.put("projectId", request.getHeader("projectId"));
        User user = this.userService.getUserByParams(userParam);
        if(user == null){
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "来访人信息获取失败,请确认已经授权登录");
            return rm;
        }
        Map map = new HashMap();
        Integer userId = user.getId();
        map.put("userId", userId);
        map.put("projectId", request.getHeader("projectId"));
        page = Integer.valueOf(0);
        rows = Integer.valueOf(0);
        PageInfo inviteMap = this.visitorApplyService.getMyApplyList(map, page, rows);
        List<Map<String, Object>> inviteMapList = inviteMap.getList();
        for (Map<String, Object> map2 : inviteMapList) {
            String status = (String) map2.get("status");
            if (!status.equals("已取消")) {
            }

        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            String chunsunProjectId = PropertyUtil.getProperty("chunsun_project_id");
            List list = new ArrayList();
            Map params = new HashMap();
            params.put("toComName", visitor.getCompanyName());
            params.put("toEmpName", visitor.getVisited());
            params.put("toEmpMobile", visitor.getVisitedPhone());
            String floor = "";
            String floorInfo = visitor.getFloor();
            Pattern pattern = Pattern.compile("^(\\d+)");
            if (!StringUtils.isEmpty(floorInfo)) {
                Matcher matcher = pattern.matcher(floorInfo);
                if (matcher.find()) {
                    floor = matcher.group();
                }
            }
            if (projectId.equals(chunsunProjectId)) {
                floor = !StringUtils.isEmpty(floor) ? floor : "1";
            }
            params.put("toFloor", floor);
            params.put("visitorName", visitor.getVisitorName());
            params.put("visitorPhone", visitor.getVisitorPhone());
            params.put("visitorCertNo", visitor.getVisitorCard());
            params.put("peopleCount", visitor.getVisitorNum());
            String reason = visitor.getVisitedCasue();
            if(StringUtils.isEmpty(reason)){
                reason = "商务洽谈";
            }
            params.put("visitReason", reason);
            params.put("toDept", "");
            params.put("visitDate", visitor.getCreatetime());
            String chunsunHost = PropertyUtil.getProperty("visitor_a_url");
            String http;
            params.put("startTime", visitor.getStartTime()+":00");
            params.put("endTime", visitor.getEndTime()+":00");
            if (projectId.equals(chunsunProjectId)) {
                long time = System.currentTimeMillis();
                params.put("time", time);
                // 签名
                String signKey = PropertyUtil.getProperty("sign_key");// 约定密钥
                String str = JSON.toJSONString(params);
                str = str + "&key=" + signKey;
                String md5Str = MD5Util.crypt(str).toUpperCase();
                params.put("sign", md5Str);
                this.log.info("========访客预约：二维码入参====：" + JSONObject.toJSONString(params));
                JSONObject returnJson = HttpRequestUtils.httpPost(chunsunHost + "/api/Getqrcode", JSON.toJSONString(params));
                http = returnJson != null ? returnJson.toJSONString() : "";
            } else {
                this.log.info("========访客预约：二维码入参====：" + JSONObject.toJSONString(params));
                http = HttpRequestUtils.http(getBcdApiHost(projectId) + "/api/Getqrcode", params);
            }
            this.log.info("========访客预约：二维码返回====：" + http);
            if ("0".equals(String.valueOf(JSONObject.parseObject(http).get("errcode")))) {
                JSONObject retdata = JSONObject.parseObject(http).getJSONObject("Retdata");
                if (projectId.equals(chunsunProjectId)) {
                    String qrcodeNo = retdata.getString("qrcodeNo");
                    System.out.println("========访客预约：春笋二维码标记====：" + qrcodeNo);
                    list.add(qrcodeNo);
                } else {
                    String qrcode = retdata.getString("qrcodeAddress");
                    System.out.println("========访客预约：BCD二维码地址====：" + qrcode);
                    list.add(URLUtil.replaceLanToWan(qrcode, getBcdApiHost(projectId)));
                }
            } else {
                rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
                this.log.error("生成二维码失败,申请异常！");
                return rm;
            }

            String otherVistorName = visitor.getOtherVistorName();
            if (otherVistorName != null) {
                String[] strArray = otherVistorName.split("、");
                for (int i = 0; i < strArray.length; i++) {
                    Map jsonCode = new HashMap();
                    jsonCode.put("toComName", visitor.getCompanyName());
                    jsonCode.put("toEmpName", visitor.getVisited());
                    jsonCode.put("toEmpMobile", visitor.getVisitedPhone());
                    jsonCode.put("toFloor", floor);
                    jsonCode.put("visitorName", strArray[i]);
                    jsonCode.put("visitorPhone", visitor.getVisitorPhone());
                    jsonCode.put("visitorCertNo", visitor.getVisitorCard());
                    jsonCode.put("peopleCount", visitor.getVisitorNum());
                    jsonCode.put("visitReason", visitor.getVisitedCasue());
                    jsonCode.put("toDept", "");
                    jsonCode.put("visitDate", visitor.getCreatetime());

                    String http2;
                    jsonCode.put("startTime", visitor.getStartTime());
                    jsonCode.put("endTime", visitor.getEndTime());
                    if (projectId.equals(chunsunProjectId)) {
                        long time = System.currentTimeMillis();
                        params.put("time", time);
                        // 签名
                        String signKey = PropertyUtil.getProperty("sign_key");// 约定密钥
                        String str = JSON.toJSONString(jsonCode) + "&key=" + signKey;
                        String md5Str2 = MD5Util.crypt(str).toUpperCase();
                        jsonCode.put("sign", md5Str2);
                        this.log.info("========访客预约：春笋二维码入参====：" + JSONObject.toJSONString(jsonCode));
                        JSONObject returnJson = HttpRequestUtils.httpPost(chunsunHost + "/api/Getqrcode", JSON.toJSONString(jsonCode));
                        http2 = returnJson != null ? returnJson.toJSONString() : "";
                    } else {
                        this.log.info("========访客预约：BCD二维码入参====：" + JSONObject.toJSONString(jsonCode));
                        http2 = HttpRequestUtils.http(getBcdApiHost(projectId) + "/api/Getqrcode", jsonCode);
                    }
                    this.log.info("========访客预约：二维码返回====：" + http2);
                    if ("0".equals(String.valueOf(JSONObject.parseObject(http2).get("errcode")))) {
                        JSONObject retdata = JSONObject.parseObject(http2).getJSONObject("Retdata");
                        if (projectId.equals(chunsunProjectId)) {
                            String qrcodeNo = retdata.getString("qrcodeNo");
                            System.out.println("========访客预约：春笋二维码标记====：" + qrcodeNo);
                            list.add(qrcodeNo);
                        } else {
                            String qrcode = retdata.getString("qrcodeAddress");
                            System.out.println("========访客预约：BCD二维码地址====：" + qrcode);
                            list.add(URLUtil.replaceLanToWan(qrcode, getBcdApiHost(projectId)));
                        }
                    } else {
                        rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
                        this.log.error("生成二维码失败,申请异常！");
                        return rm;
                    }

                }
            }
            String symbol = Joiner.on(",").join(list);

            VisitorApply visitorApply = new VisitorApply();
            visitorApply.setVisitorName(visitor.getVisitorName());
            visitorApply.setVisitorPhone(visitor.getVisitorPhone());
            visitorApply.setVisitorCard(visitor.getVisitorCard());
            visitorApply.setVisitorNum(visitor.getVisitorNum());
            visitorApply.setStartTime(sdf.parse(visitor.getStartTime()));
            visitorApply.setEndTime(sdf.parse(visitor.getEndTime()));
            visitorApply.setVisited(visitor.getVisited());
            visitorApply.setVisitedPhone(visitor.getVisitedPhone());
            visitorApply.setVisitedCompanyPosition(visitor.getVisitedCompanyPosition());
            visitorApply.setVisitedCasue(visitor.getVisitedCasue());
            visitorApply.setFloor(floor);
            visitorApply.setOtherVistorName(visitor.getOtherVistorName());
            visitorApply.setApplytype(Integer.valueOf(1));
            visitorApply.setCreateDate(new Date());
            visitorApply.setTwoDimension(symbol);
            visitorApply.setStatus("待审批");
            visitorApply.setStatuscode(Integer.valueOf(0));

            this.visitorApplyService.save(visitorApply);
            ApplyRecord entity = new ApplyRecord();
            entity.setApplyId(visitorApply.getId());
            entity.setUserId(user.getId());
            entity.setTitle("预约申请");

            entity.setApplyType("访客预约申请");
            entity.setInterviewee(visitor.getVisited());
            entity.setTypeCode(Integer.valueOf(5));
            entity.setStatus("已提交");
            entity.setCreateDate(new Date());
            entity.setDescription(visitor.getVisitedCasue());
            entity.setProjectId(request.getHeader("projectId"));
            entity.setSynId(request.getHeader("synId"));
            entity.setSynMainId(request.getHeader("synMainId"));

            this.applyRecordService.save(entity);
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
            rm.setData("申请提交成功！");
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("申请异常！");
            e.printStackTrace();
        }

        return rm;
    }

    @ApiOperation(value = "预约列表", notes = "预约列表")
    @RequestMapping(value = {"/getMyApplyList"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<PageInfo<Map<String, Object>>> getMyApplyList(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            Map userParam = new HashMap();
            userParam.put("openId", req.getHeader("openId"));
            userParam.put("projectId", req.getHeader("projectId"));
            User user = this.userService.getUserByParams(userParam);
            Integer userId = user.getId();
            map.put("userId", userId);
            map.put("projectId", req.getHeader("projectId"));
            Integer page = (Integer) map.get("page");
            Integer rows = (Integer) map.get("rows");
            PageInfo inviteMap = this.visitorApplyService.getMyApplyList(map, page, rows);
            rm.setData(inviteMap);
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("预约列表异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "再一次申请", notes = "再一次申请")
    @RequestMapping(value = {"/applyAgain"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> applyAgain(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            Map inviteMap = this.visitorApplyService.getVisitorApplyId(map);
            String projectId = req.getHeader("projectId");
            List list = new ArrayList();
            Map params = new HashMap();
            params.put("toComName", inviteMap.get("visitedCompanyPosition"));
            params.put("toEmpName", inviteMap.get("visited"));
            params.put("toEmpMobile", inviteMap.get("visitedPhone"));
            params.put("toFloor", inviteMap.get("floor"));
            params.put("visitorName", inviteMap.get("visitorName"));
            params.put("visitorPhone", inviteMap.get("visitorPhone"));
            params.put("visitorCertNo", inviteMap.get("visitorCard"));
            params.put("peopleCount", inviteMap.get("visitorNum"));
            params.put("visitReason", inviteMap.get("visitedCasue"));
            params.put("toDept", "");
            params.put("visitDate", inviteMap.get("startTime"));

            String chunsunHost = PropertyUtil.getProperty("visitor_a_url");
            String http;
            String chunsunProjectId = PropertyUtil.getProperty("chunsun_project_id");
            if (projectId.equals(chunsunProjectId)) {
                long time = System.currentTimeMillis();
                params.put("time", time);
                // 签名
                String signKey = PropertyUtil.getProperty("sign_key");// 约定密钥
                String str = JSON.toJSONString(params);
                str = str + "&key=" + signKey;
                String md5Str = MD5Util.crypt(str).toUpperCase();
                params.put("sign", md5Str);
                this.log.info(new StringBuilder().append("========访客邀请：春笋二维码入参====：").append(JSONObject.toJSONString(params)).toString());
                JSONObject returnJson = HttpRequestUtils.httpPost(chunsunHost + "/api/Getqrcode", JSON.toJSONString(params));
                http = returnJson != null ? returnJson.toJSONString() : "";
            } else {
                params.put("startTime", inviteMap.get("startTime"));
                params.put("endTime", inviteMap.get("endTime"));
                this.log.info("========再次预约申请：BCD二维码入参====：" + JSONObject.toJSONString(params));
                http = HttpRequestUtils.http(getBcdApiHost(projectId) + "/api/Getqrcode", params);
            }
            this.log.info(new StringBuilder().append("========再次预约申请：二维码返回====：").append(http).toString());
            if ("0".equals(String.valueOf(JSONObject.parseObject(http).get("errcode")))) {
                JSONObject retdata = JSONObject.parseObject(http).getJSONObject("Retdata");
                if (projectId.equals(chunsunProjectId)) {
                    String qrcodeNo = retdata.getString("qrcodeNo");
                    System.out.println("========再次预约申请：春笋二维码标记====：" + qrcodeNo);
                    list.add(qrcodeNo);
                } else {
                    String qrcode = retdata.getString("qrcodeAddress");
                    System.out.println("========再次预约申请：BCD二维码地址====：" + qrcode);
                    list.add(URLUtil.replaceLanToWan(qrcode, getBcdApiHost(projectId)));
                }
            }

            String otherVistorName = (String) inviteMap.get("otherVistorName");
            if (otherVistorName != null) {
                String[] strArray = otherVistorName.split("、");
                for (int i = 0; i < strArray.length; i++) {
                    Map jsonCode = new HashMap();
                    jsonCode.put("toComName", inviteMap.get("visitedCompanyPosition"));
                    jsonCode.put("toEmpName", inviteMap.get("visited"));
                    jsonCode.put("toEmpMobile", inviteMap.get("visitedPhone"));
                    jsonCode.put("toFloor", inviteMap.get("floor"));
                    jsonCode.put("visitorName", inviteMap.get("visitorName"));
                    jsonCode.put("visitorPhone", inviteMap.get("visitorPhone"));
                    jsonCode.put("visitorCertNo", inviteMap.get("visitorCard"));
                    jsonCode.put("peopleCount", inviteMap.get("visitorNum"));
                    jsonCode.put("visitReason", inviteMap.get("visitedCasue"));
                    jsonCode.put("toDept", "");
                    jsonCode.put("visitDate", inviteMap.get("startTime"));

                    String http2;
                    if (projectId.equals(chunsunProjectId)) {
                        long time = System.currentTimeMillis();
                        params.put("time", time);
                        // 签名
                        String signKey = PropertyUtil.getProperty("sign_key");// 约定密钥
                        String str = JSON.toJSONString(jsonCode) + "&key=" + signKey;
                        String md5Str2 = MD5Util.crypt(str).toUpperCase();
                        jsonCode.put("sign", md5Str2);
                        this.log.info("========再次预约申请：二维码入参====：" + JSONObject.toJSONString(jsonCode));
                        JSONObject returnJson = HttpRequestUtils.httpPost(chunsunHost + "/api/Getqrcode", JSON.toJSONString(jsonCode));
                        http2 = returnJson != null ? returnJson.toJSONString() : "";
                    } else {
                        jsonCode.put("startTime", inviteMap.get("startTime"));
                        jsonCode.put("endTime", inviteMap.get("endTime"));
                        this.log.info("========再次预约申请：二维码入参====：" + JSONObject.toJSONString(jsonCode));
                        http2 = HttpRequestUtils.http(getBcdApiHost(projectId) + "/api/Getqrcode", jsonCode);
                    }
                    this.log.info("========再次预约申请：二维码返回====：" + http2);
                    if ("0".equals(String.valueOf(JSONObject.parseObject(http2).get("errcode")))) {
                        JSONObject retdata = JSONObject.parseObject(http2).getJSONObject("Retdata");
                        if (projectId.equals(chunsunProjectId)) {
                            String qrcodeNo = retdata.getString("qrcodeNo");
                            System.out.println("========再次预约申请：春笋二维码标记====：" + qrcodeNo);
                            list.add(qrcodeNo);
                        } else {
                            String qrcode = retdata.getString("qrcodeAddress");
                            System.out.println("========再次预约申请：BCD二维码地址====：" + qrcode);
                            list.add(URLUtil.replaceLanToWan(qrcode, getBcdApiHost(projectId)));
                        }
                    }
                }
            }
            String symbol = Joiner.on(",").join(list);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            VisitorApply visitorApply = new VisitorApply();
            visitorApply.setVisitorName((String) inviteMap.get("visitorName"));
            visitorApply.setVisitorPhone((String) inviteMap.get("visitorPhone"));
            visitorApply.setVisitorNum((Integer) inviteMap.get("visitorNum"));
            visitorApply.setStartTime(format.parse(format.format((Long) inviteMap.get("startTime"))));
            visitorApply.setEndTime(format.parse(format.format((Long) inviteMap.get("endTime"))));
            visitorApply.setVisited((String) inviteMap.get("visited"));
            visitorApply.setVisitedPhone((String) inviteMap.get("visitedPhone"));
            visitorApply.setVisitedCompanyPosition((String) inviteMap.get("visitedCompanyPosition"));
            visitorApply.setVisitedCasue((String) inviteMap.get("visitedCasue"));
            visitorApply.setFloor((String) inviteMap.get("floor"));
            visitorApply.setOtherVistorName((String) inviteMap.get("otherVistorName"));
            visitorApply.setApplytype(Integer.valueOf(1));
            visitorApply.setCreateDate(new Date());
            visitorApply.setTwoDimension(symbol);
            visitorApply.setStatus("待审批");
            visitorApply.setStatuscode(Integer.valueOf(0));

            this.visitorApplyService.save(visitorApply);
            ApplyRecord record = new ApplyRecord();
            Map userParam = new HashMap();
            userParam.put("openId", req.getHeader("openId"));
            User user = this.userService.getUserByParams(userParam);
            record.setApplyId(visitorApply.getId());
            record.setUserId(user.getId());
            record.setTitle("预约申请");

            record.setApplyType("访客预约申请");
            record.setInterviewee((String) inviteMap.get("visited"));
            record.setTypeCode(Integer.valueOf(5));
            record.setStatus("已提交");
            record.setCreateDate(new Date());

            this.applyRecordService.save(record);
            rm.setData("申请成功");
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("申请异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "预约列表详情", notes = "预约列表详情")
    @RequestMapping(value = {"/getVisitorApplyListDetail"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Map<String, Object>> getVisitorApplyListDetail(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            VisitorApply entity = new VisitorApply();
            entity.setId((Integer) map.get("applyId"));
            entity.setIsRead(1);
            this.visitorApplyService.update(entity);
            Map inviteMap = this.visitorApplyService.getVisitorApplyId(map);
            Long endTime = (Long) inviteMap.get("endTime");
            long newTime = new Date().getTime() / 1000L;
            String status = (String) inviteMap.get("status");
            Integer statusCode = (Integer) inviteMap.get("statusCode");
            if (!status.equals("已取消")) {
                if (endTime.longValue() < newTime) {
                    inviteMap.replace("statusCode", Integer.valueOf(3));

                    if (statusCode.intValue() == 0) {
                        inviteMap.replace("statusCode", Integer.valueOf(7));
                    }
                }
            } else {
                inviteMap.replace("statusCode", Integer.valueOf(4));
            }

            rm.setData(inviteMap);
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("邀约申请详情异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "邀请我的详情", notes = "邀请我的详情")
    @RequestMapping(value = {"/getVisitorApplyDetail"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Map<String, Object>> getVisitorApplyDetail(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            VisitorApply entity = new VisitorApply();
            entity.setId((Integer) map.get("applyId"));
            entity.setIsRead(1);
            this.visitorApplyService.update(entity);
            Map inviteMap = this.visitorApplyService.getVisitorApplyId(map);
            Long endTime = (Long) inviteMap.get("endTime");
            Long startTime = (Long) inviteMap.get("startTime");
            long newTime = new Date().getTime() / 1000L;
            String status = (String) inviteMap.get("status");
            if (!"已取消".equals(status)) {
                if (newTime < startTime.longValue()) {
                    inviteMap.put("statusCode", 5);
                } else if (endTime.longValue() < newTime) {
                    inviteMap.put("statusCode", 3);
                } else {
                    inviteMap.put("statusCode", 6);
                }
            } else {
                inviteMap.put("statusCode", 4);
            }

            rm.setData(inviteMap);
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("邀约申请详情异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "邀请我的", notes = "邀请我的")
    @RequestMapping(value = {"/getMyInvited"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<PageInfo<Map<String, Object>>> getMyInvited(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            Map userParam = new HashMap();
            userParam.put("openId", req.getHeader("openId"));
            userParam.put("projectId", req.getHeader("projectId"));
            User user = this.userService.getUserByParams(userParam);
            String wxPhone = user.getWxPhone();
            map.put("wxPhone", wxPhone);
            map.put("projectId", req.getHeader("projectId"));
            Integer page = (Integer) map.get("page");
            Integer rows = (Integer) map.get("rows");
            PageInfo inviteMap = this.visitorApplyService.getMyInvited(map, page, rows);
            rm.setData(inviteMap);

            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("我的邀请异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "取消邀约", notes = "取消邀约")
    @RequestMapping(value = {"/cancelInvited"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> cancelInvited(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            map.put("updateDate", new Date());
            map.put("status", "已取消");
            int flag = this.visitorApplyService.cancelInviteId(map);
            if (flag > 0) {
                VisitorApply entity = new VisitorApply();
                Date updateDate = (Date) map.get("updateDate");
                String id = (String) map.get("id");
                entity.setUpdateDate(updateDate);
                entity.setId(Integer.valueOf(id));
                this.visitorApplyService.update(entity);
            }
            rm.setData("取消成功");
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("邀约申请详情异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "刷新二维码", notes = "刷新二维码")
    @RequestMapping(value = {"/refreshCode"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> refreshCode(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            int index = ((Integer) map.get("index")).intValue();
            String projectId = req.getHeader("projectId");
            Map inviteMap = this.visitorApplyService.getVisitorApplyId(map);
            String twoDimension = (String) inviteMap.get("twoDimension");
            String[] staffIds = twoDimension.split(",");
            String oldCode = staffIds[index].substring(staffIds[index].lastIndexOf("=") + 1);
            System.out.println(oldCode);

            Map jsoncode = new HashMap();
            jsoncode.put("qrcodeNo", oldCode);
            String http = HttpRequestUtils.http(getBcdApiHost(projectId) + "/api/getTwoCode", jsoncode);
            String qrcodePath = JSONObject.parseObject(http).getJSONObject("Retdata").getString("qrcodeAddress");
            String newCode = JSONObject.parseObject(http).getJSONObject("Retdata").getString("qrcodeNo");
            map.put("newCode", newCode);
            map.put("oldCode", oldCode);

            this.visitorApplyService.updateCode(map);
            rm.setData(URLUtil.replaceLanToWan(qrcodePath, getBcdApiHost(projectId)));
            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("更新异常！");
            e.printStackTrace();
        }
        return rm;

    }

    @ApiOperation(value = "验证凭证", notes = "验证凭证")
    @RequestMapping(value = {"/getCheckCode"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage getCheckCode(@RequestBody JSONObject param) {
        ResponseMessage rm = new ResponseMessage();
        try {
            Integer code = (Integer) param.get("code");
            Integer applyId = (Integer) param.get("applyId");
            RedisUtils redisUtils = SpringUtils.getBean(RedisUtils.class);
            String verifyCode = redisUtils.getObj("invite_visitor_" + applyId);
            if (code == null || !verifyCode.equals(String.valueOf(code))) {
                rm.setCodeAndMsg(ResultCodeValue.R_INVALID_ERROR, "-2");
                rm.setMessage("验证码有误，请重新输入");
                return rm;
            }
            rm.setCodeAndMsg(ResultCodeValue.R_SUCCESS, "验证成功");
            rm.setData(-1);
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("验证异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "获取通行码", notes = "获取通行码")
    @RequestMapping(value = {"/getMeCode"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> getMeCode(@RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            Integer code = (Integer) map.get("code");
            String projectId = (String) map.get("projectId");
            Integer applyId = (Integer) map.get("applyId");
            if (StringUtils.isEmpty(projectId)) {
                rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "项目id未空");
                return rm;
            }
            Map visitorApply = this.visitorApplyService.getVisitorApplyId(map);
            Long endTime = (Long) visitorApply.get("endTime");
            Long startTime = (Long) visitorApply.get("startTime");
            long newTime = new Date().getTime() / 1000L;
            String status = (String) visitorApply.get("status");
            Map resultMap = new HashMap();
            resultMap.put("startTime", startTime);
            resultMap.put("endTime", endTime);
            if (!status.equals("已取消")) {
                if (newTime < startTime) {
                    rm.setData(resultMap);
                    rm.setMessage("-3"); // 未到拜访时间，暂时无法查看二维码
                } else if (endTime < newTime) {
                    rm.setData(resultMap);
                    rm.setMessage("-4"); // 访问时间已过，凭证已失效
                } else {
                    String twoDimension = (String) visitorApply.get("twoDimension");
                    resultMap.put("twoCode", twoDimension);
                    resultMap.put("startTime", startTime);
                    resultMap.put("endTime", endTime);
                    rm.setData(resultMap);
                    rm.setMessage("-1"); // 正确
                }
            } else {
                rm.setData(resultMap);
                rm.setMessage("-5"); // 邀约已被取消
            }

        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("获取通行码异常！");
            e.printStackTrace();
        }
        rm.setCode(ResultCodeEnum.SUCCESS.code);
        return rm;
    }

    @ApiOperation(value = "验证凭证", notes = "验证凭证")
    @RequestMapping(value = {"/getVoucher"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> getVoucher(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            String mobile = (String) map.get("mobile");
            Integer applyId = (Integer) map.get("applyId");
            if (!VerityUtil.isMobile(mobile)) {
                rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, "请输入正确的手机号码");
                return rm;
            }

            Map visitorApplyId = this.visitorApplyService.getVisitorApplyId(map);
            String visitorPhone = (String) visitorApplyId.get("visitorPhone");
            if (mobile.equals(visitorPhone)) {
                Map param = this.visitorApplyService.findValidate(map);
                if (param != null) {
                    ValidateInfo entity = new ValidateInfo();
                    entity.setApplyid(applyId);
                    entity.setIsreceive(Integer.valueOf(1));
                    entity.setWxphone(mobile);
                    this.validateInfoService.save(entity);

                    rm.setData("验证成功");
                    rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
                } else {
                    rm.setData("验证失败");
                    rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
                }
            } else {
                rm.setData("手机号和邀约信息不一致，请检查手机号或联系邀约人");
                rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            }
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("验证异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "验证凭证", notes = "验证凭证")
    @RequestMapping(value = {"/isReceive"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> isReceive(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            String openId = req.getHeader("openId");
            Map param = new HashMap();
            param.put("openId", openId);
            User user = this.userService.getUserByParams(param);
            Integer admin = user.getAdmin();
            if (admin.intValue() == 4) {
                List<ValidateInfo> findList = this.validateInfoService.findList(map);
                if (findList.size() > 0) {
                    for (ValidateInfo validateInfo : findList) {
                        if (validateInfo.getIsreceive().intValue() == 1) {
                            rm.setData(Integer.valueOf(-1));
                            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
                        }
                    }
                } else {
                    rm.setData(Integer.valueOf(-2));
                    rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
                }
            } else {
                rm.setData(Integer.valueOf(-1));
                rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
            }
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("验证异常！");
            e.printStackTrace();
        }
        return rm;
    }

    @ApiOperation(value = "微信号是否一致", notes = "微信号是否一致")
    @RequestMapping(value = {"/isConsistent"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<Object> isConsistent(HttpServletRequest req, @RequestBody Map<String, Object> map) {
        ResponseMessage rm = new ResponseMessage();
        try {
            String openId = req.getHeader("openId");
            Map param = new HashMap();
            param.put("openId", openId);
            User user = this.userService.getUserByParams(param);
            Integer admin = user.getAdmin();
            if (admin.intValue() == 4) {
                String wxPhone = (String) map.get("wxPhone");
                List<ValidateInfo> findList = this.validateInfoService.findList(map);
                if (findList.size() > 0) {
                    for (ValidateInfo validateInfo : findList) {
                        if (validateInfo.getWxphone().equals(wxPhone)) {
                            rm.setData(Integer.valueOf(-1));
                            rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
                            return rm;
                        }
                    }
                    rm.setData(Integer.valueOf(-2));
                    rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
                } else {
                    rm.setData(Integer.valueOf(-2));
                    rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
                }
            } else {
                rm.setData(Integer.valueOf(-2));
                rm.setCodeAndMsg(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg);
            }
        } catch (Exception e) {
            rm.setCodeAndMsg(ResultCodeEnum.ERROR.code, ResultCodeEnum.ERROR.msg);
            this.log.error("验证异常！");
            e.printStackTrace();
        }
        return rm;
    }

    private static boolean isOverlap(String startdate1, String enddate1, String startdate2, String enddate2) {
        Date leftStartDate = null;
        Date leftEndDate = null;
        Date rightStartDate = null;
        Date rightEndDate = null;
        try {
            leftStartDate = DateUtils.getDateByStr(startdate1);
            leftEndDate = DateUtils.getDateByStr(enddate1);
            rightStartDate = DateUtils.getDateByStr(startdate2);
            rightEndDate = DateUtils.getDateByStr(enddate2);
        } catch (Exception e) {
            return false;
        }

        return ((leftStartDate.getTime() >= rightStartDate.getTime()) &&
                (leftStartDate
                        .getTime() < rightEndDate.getTime())) ||
                ((leftStartDate
                        .getTime() > rightStartDate.getTime()) &&
                        (leftStartDate
                                .getTime() <= rightEndDate.getTime())) ||
                ((rightStartDate
                        .getTime() >= leftStartDate.getTime()) &&
                        (rightStartDate
                                .getTime() < leftEndDate.getTime())) || (
                (rightStartDate
                        .getTime() > leftStartDate.getTime()) &&
                        (rightStartDate
                                .getTime() <= leftEndDate.getTime()));
    }

    private String getBcdApiHost(String projectId) {
        if (projectId.equals(PropertyUtil.getProperty("huarun_b_project_id"))) {
            return PropertyUtil.getProperty("visitor_b_url");
        }
        if (projectId.equals(PropertyUtil.getProperty("huarun_c_project_id"))) {
            return PropertyUtil.getProperty("visitor_c_url");
        }
        if (projectId.equals(PropertyUtil.getProperty("huarun_d_project_id"))) {
            return PropertyUtil.getProperty("visitor_d_url");
        }
        return PropertyUtil.getProperty("visitor_bcd_url");
    }

    private String crypt(String str) {
        if ((str == null) || (str.length() == 0)) {
            throw new IllegalArgumentException("String to encript cannot be null or zero length");
        }
        StringBuffer hexString = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            byte[] hash = md.digest();
            for (int i = 0; i < hash.length; i++) {
                if ((0xFF & hash[i]) < 16) {
                    hexString.append("0" + Integer.toHexString(0xFF & hash[i]));
                } else {
                    hexString.append(Integer.toHexString(0xFF & hash[i]));
                }
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hexString.toString();
    }
}
